<?php
declare(strict_types=1);

namespace App\Service;

use App\Helper\Log;
use App\Helper\Util;
use Hyperf\DbConnection\Db;
use App\Helper\Calendar;
use App\Service\UserService;
use App\Service\WxTemplateMessageService;
use App\Service\StatisrecService;

/**
 * 系统文案服务
 */
class CopyrightService 
{
    private $office_id = 0;
    /**
     * [__construct description] 构造函数
     */
    public function __construct()
    {
    }
    /**
     * 分享文案
     * [shareCopyright description]
     * @param  [type] $type   [description]
     * @param  [type] $params [description]
     * @return [type]         [description]
     */
    public function shareCopyright($type,$params)
    {
        $return_data = [];
        switch ($type) {
            case 'share_tool':
                $return_data = $this->shareTool($params);
                break;
            case 'share_trad':
                $return_data = $this->shareTrad($params);
                break;
            case 'invite_join':
                $return_data = $this->inviteJoin($params);
                break;
        }
        return $return_data;
    }
    /**
     * 分享工具
     * [shareTool description]
     * @param  [type] $params [description]
     * @return [type]         [description]
     */
    public function shareTool($params)
    {
        $return_data = [
            'title' => '我发现了一个很好用的排班工具，分享给你！',
            'words' => '',
            'icon' => '',
            'image' => env('QINIU_URL').'supaiban/share/share1.png',
            'params' => $params,
            'extends' => [
                'other'=>NULL
            ],
            'land' => [
                'url'=>'',
                'page'=>'',
                'path'=>''
            ],
        ];
        return $return_data;
    }
    /**
     * 分享排班
     * [shareTrad description]
     * @param  [type] $params [description]
     * @return [type]         [description]
     */
    public function shareTrad($params)
    {
        $user_id = $params['user_id']??0;
        $user_info = Db::table('user')
            ->select(['realname'])
            ->where(['id'=>$user_id])
            ->first();
        $office_id = $params['office_id']??0;
        $office_info = Db::table('office')
            ->select(['name'])
            ->where(['id'=>$office_id])
            ->first();
        $begin_date = $params['begin_date']??'-';
        $end_date = $params['end_date']??'-';
        $return_data = [
            'title' => $user_info['realname'].'分享了'.$office_info['name']." ".$begin_date.'至'.$end_date.'的排班',
            'words' => '',
            'icon' => '',
            'image' => env('QINIU_URL').'supaiban/share/share1.png',
            'params' => $params,
            'extends' => [
                'other'=>NULL
            ],
            'land' => [
                'url'=>'',
                'page'=>'',
                'path'=>''
            ],
        ];
        return $return_data;
    }
    /**
     * 邀请加入
     * [inviteJoin description]
     * @return [type] [description]
     */
    public function inviteJoin($params)
    {
        $user_id = $params['user_id']??0;
        $user_info = Db::table('user')
            ->select(['realname'])
            ->where(['id'=>$user_id])
            ->first();
        $office_id = $params['office_id']??0;
        $office_info = Db::table('office')
            ->select(['name'])
            ->where(['id'=>$office_id])
            ->first();
        $return_data = [
            'title' => $user_info['realname'].'邀请你加入'.$office_info['name'],
            'words' => '',
            'icon' => '',
            'image' => env('QINIU_URL').'supaiban/share/share1.png',
            'params' => $params,
            'extends' => [
                'other'=>NULL
            ],
            'land' => [
                'url'=>'',
                'page'=>'',
                'path'=>''
            ],
        ];
        return $return_data;
    }
}
